package com.chencs.common.lmadmin.controller;


import com.alibaba.fastjson.JSON;
import com.chencs.common.lmadmin.service.LmMemberService;
import com.chencs.common.lmadmin.service.LmSubjectService;
import com.chencs.vo.biz.lianmeng.LmMember;
import com.chencs.vo.biz.lianmeng.LmProduct;
import com.chencs.vo.biz.lianmeng.LmSubject;
import com.chencs.vo.biz.lianmeng.LmSubject_Pro;
import com.chencs.vo.net.response.ResponseBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/m/lmSubject")
public class LmSubjectController {


    Logger logger = LoggerFactory.getLogger(LmSubjectController.class);


    @Autowired
    private LmSubjectService lmSubjectService;
    @RequestMapping(value = "/getList", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String subjectList() {
        List<LmSubject> subjectList = lmSubjectService.subjec_List();
        return JSON.toJSON(subjectList).toString();
    }

    @RequestMapping(value = "/getSubject", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String subject(@RequestBody String id) {
        LmSubject subject = lmSubjectService.findSubjectBySid(id);
        return JSON.toJSON(subject).toString();
    }

    @RequestMapping(value = "/getProductBySid", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getProductBySid(@RequestBody String sid) {
        List<LmProduct> products = lmSubjectService.getProductBySid(sid);
        return JSON.toJSON(products).toString();
    }


    @RequestMapping(value = "/delSubjectProById", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String delSubjectProById(@RequestBody String id) {
        ResponseBase response = new ResponseBase();
          lmSubjectService.delSubjectProById(id);
        response.setMsg("专题商品删除成功");
        return JSON.toJSON(response).toString();
    }

    @RequestMapping(value = "/delSubjectBySid", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String delSubjectBySid(@RequestBody String sid) {
        ResponseBase response = new ResponseBase();
        lmSubjectService.delSubjectBySid(sid);
        response.setMsg("专题删除成功");
        return JSON.toJSON(response).toString();
    }


    @RequestMapping(value = "/insertSubject", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String insertSubject(@RequestBody LmSubject subject) {
        ResponseBase response = new ResponseBase();
        lmSubjectService.insertSubject(subject);
        response.setMsg("专题添加成功");
        return JSON.toJSON(response).toString();
    }


    @RequestMapping(value = "/insertSubjectPro", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String insertSubjectPro(@RequestBody LmSubject_Pro subject_pro) {
        ResponseBase response = new ResponseBase();
        lmSubjectService.insertSubjectPro(subject_pro);
        response.setMsg("专题商品添加成功");
        return JSON.toJSON(response).toString();
    }


    @RequestMapping(value = "/updateSubject", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String updateSubject(@RequestBody LmSubject subject) {
        ResponseBase response = new ResponseBase();
        lmSubjectService.updateSubject(subject);
        response.setMsg("专题修改成功");
        return JSON.toJSON(response).toString();
    }




}
